<?php



	class News extends CI_Model

	{

		function __construct()

		{

			parent::__construct();

		}



		function getAll($limit = false)
		{
			$this->db->select('*');
			$this->db->from('tghm_news');
			$this->db->where('active','1');
			$this->db->order_by('id','desc');					

			if($limit)
			{
				$this->db->limit($limit, 0);
			}			

			$query = $this->db->get();

			return $query->result_array();
		}



		function addNew($data)

		{

			return $this->db->insert('tghm_news',$data);

		}



		function getNew($id = false)

		{

			$query = $this->db->get_where('tghm_news',array('id'=>$id));

			return $query->row_array();

		}

		function getLastID()
		{
			$query = $this->db->query('SELECT id FROM tghm_news ORDER BY id DESC LIMIT 1');

			$last_id = '';

			foreach ($query->result() as $row) 
			{
				$last_id = $row->id;
			}

			return $last_id;
		}

	}